import wiringpi as gpio
import time
from digital_tube import init, display_num, display, close

init()
gpio.pinMode(40, gpio.INPUT)
gpio.pullUpDnControl(40, gpio.PUD_UP)
try:
	while True:
		t, h = 0, 0
		try:
			with open('temp.txt', 'r') as f:
				t, h = f.read().strip().split(',')
		except Exception as e:
			print(e)
			continue
		t = float(t)
		h = float(h)
		if gpio.digitalRead(40) == 1:
			display_num(t)
		else:
			display_num(h)
		gpio.delay(1)
except KeyboardInterrupt:
	close()
	


